﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Common;
using Dao;
using Domain.Common;
using Domain.Officers;
using Microsoft.Xna.Framework;

namespace Domain
{
    /// <summary>
    /// 军阀势力
    /// </summary>
    public partial class Force
    {
        /// <summary>
        /// 玩家势力
        /// </summary>
        public static Force PlayForce;
        /// <summary>
        /// 当前运行工作任务的势力
        /// </summary>
        public static Force CurrentWorkForce;
        public static Dictionary<short, Force> Forces = new Dictionary<short, Force>();
        public short Id { get; set; }
        public string Name { get; set; }
        public string FirstName { get; set; }
        public bool Passed { get; set; }
        /// <summary>
        /// 势力领导
        /// </summary>
        public short LeaderID { get; set; }
        public string ColorCode { get; set; }
        public Color Color { get; set; }
        /// <summary>
        /// 治所
        /// </summary>
        public short CapitalID { get; set; }
        /// <summary>
        /// 名声
        /// </summary>
        public int Reputation { get; set; }
        /// <summary>
        /// 是否玩家控制
        /// </summary>
        public bool Controlling { get; set; }
       
        public List<short> BuildingIds = new List<short>();
        /// <summary>
        /// 势力主公
        /// </summary>
        public Officer Master;
        /// <summary>
        /// 势力拥有的城池
        /// </summary>
        public List<Building> Buildings = new List<Building>();
       
        public static void Load()
        {
            if (Forces.Count > 0)
                return;
            DataTable tb = ForceDao.SelectAllForce("194_QXGJ.s3db");
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                DataRow dr = tb.Rows[i];
                Force force=new Force();
                force.Id= Convert.ToInt16(dr["Id"]);
                force.Name = dr["Name"].ToString();
                force.FirstName = force.Name.Substring(0, 1);
                force.Passed = Convert.ToBoolean(dr["Passed"]);
                force.LeaderID = Convert.ToInt16(dr["LeaderId"]);
                force.ColorCode = dr["ColorCode"].ToString();
                Color item = new Color();
                item.PackedValue = uint.Parse(force.ColorCode);
                force.Color = item;
                force.CapitalID = Convert.ToInt16(dr["CapitalId"]);
                force.Reputation = Convert.ToInt32(dr["Reputation"]);
                Forces.Add(force.Id,force);
            }
        }

        public static void Init()
        {
            foreach (KeyValuePair<short, Force> pair in Forces)
            {
                //设置势力主公
                if ( Officer.Officers.ContainsKey(pair.Value.LeaderID))
                {
                    Officer officer = Officer.Officers[pair.Value.LeaderID];
                    pair.Value.Master = officer;
                }
            }
        }
    }
}
